# timer_gui.py
import tkinter as tk
from tkinter import ttk, messagebox
from datetime import datetime, timedelta
from timer import Timer
from database import init_db, save_timer, get_timers, clear_timers, delete_timer_by_id
from stats import StatsAnalyzer
import calendar
import os

class TimerGUI:
    def __init__(self, root):
        self.root = root
        self.root.title("多功能计时器")
        self.root.geometry("700x550")
        self.root.resizable(True, True)
        
        # 初始化数据库
        init_db()
        
        # 创建计时器实例
        self.timer = Timer(root)
        self.timer.set_callbacks(self.update_display, self.on_complete)
        
        # 创建主容器
        self.notebook = ttk.Notebook(self.root)
        self.notebook.pack(fill=tk.BOTH, expand=True)
        style = ttk.Style()
        style.configure("TNotebook.Tab", padding=(50, 1))
        
        # 创建选项卡
        self.create_timer_tab()
        self.create_stats_tab()
        self.setup_bindings()
        
        try:
            icon_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "计时器.png")
            img = tk.PhotoImage(file=icon_path)
            self.root.iconphoto(True, img)
        except tk.TclError:
            print("图标文件未找到，使用默认图标")
                
        # 窗口关闭处理
        self.root.protocol("WM_DELETE_WINDOW", self.on_closing)

        # 新增当前时间记录
        self.current_seconds = 0

    def create_timer_tab(self):
        """创建计时器选项卡"""
        # 主容器
        tab1 = ttk.Frame(self.notebook)
        self.notebook.add(tab1, text="计时器")

        # 模式选择
        self.mode_frame = ttk.LabelFrame(tab1, text="计时模式")
        self.timer_mode = tk.StringVar(value="countup")
        ttk.Radiobutton(self.mode_frame, text="正计时", variable=self.timer_mode, 
                       value="countup", command=self.on_mode_change).grid(row=0, column=0, padx=10)
        ttk.Radiobutton(self.mode_frame, text="倒计时", variable=self.timer_mode,
                       value="countdown", command=self.on_mode_change).grid(row=0, column=1, padx=10)
        
        # 时间显示
        self.display_frame = ttk.Frame(tab1)
        self.time_label = ttk.Label(self.display_frame, text="00:00:00", font=("Arial", 48))
        self.status_label = ttk.Label(self.display_frame, text="就绪", font=("Arial", 12))
        
        # 控制按钮
        self.control_frame = ttk.Frame(tab1)
        self.start_btn = ttk.Button(self.control_frame, text="开始", command=self.start_timer)
        self.pause_btn = ttk.Button(self.control_frame, text="暂停", state=tk.DISABLED, command=self.pause_timer)
        self.stop_btn = ttk.Button(self.control_frame, text="停止", state=tk.DISABLED, command=self.stop_timer)
        self.save_btn = ttk.Button(self.control_frame, text="保存", command=self.save_timer)
        self.delete_btn = ttk.Button(self.control_frame, text="单个删除", command=self.delete_timer)
        self.clear_btn = ttk.Button(self.control_frame, text="全部清空", command=self.clear_timers)

        # 倒计时设置
        self.countdown_frame = ttk.LabelFrame(tab1, text="倒计时设置")
        self.hours_entry = ttk.Entry(self.countdown_frame, width=5)
        self.minutes_entry = ttk.Entry(self.countdown_frame, width=5)
        self.seconds_entry = ttk.Entry(self.countdown_frame, width=5)
        ttk.Label(self.countdown_frame, text="小时").grid(row=0, column=0)
        ttk.Label(self.countdown_frame, text="分钟").grid(row=0, column=2)
        ttk.Label(self.countdown_frame, text="秒").grid(row=0, column=4)
        
        # 计时列表
        self.list_frame = ttk.LabelFrame(tab1, text="保存的计时")
        self.timer_tree = ttk.Treeview(
            self.list_frame, 
            columns=('time', 'created_at'), 
            show='headings',
            height=6
        )
        self.timer_tree.heading('time', text='时间')
        self.timer_tree.heading('created_at', text='创建时间')
        self.timer_tree.column('time', width=120, anchor='center')
        self.timer_tree.column('created_at', width=200, anchor='center')
        # 配置特殊颜色标签
        self.timer_tree.tag_configure('special_pink', foreground="#E91E63")  # 00:10:30 粉色
        self.timer_tree.tag_configure('special_teal', foreground="#008080")  # 00:06:23 青色
        self.timer_tree.tag_configure('default_black', foreground="black")    # 其他黑色
        
        self.scrollbar = ttk.Scrollbar(
            self.list_frame, 
            orient="vertical", 
            command=self.timer_tree.yview
        )
        self.timer_tree.configure(yscrollcommand=self.scrollbar.set)
        self._refresh_timer_list()

        # 布局计时器选项卡
        self.mode_frame.grid(row=0, column=0, pady=10, sticky="ew")
        self.display_frame.grid(row=1, column=0, pady=15)
        self.time_label.pack()
        self.status_label.pack()
        self.control_frame.grid(row=2, column=0, pady=10)
        self.countdown_frame.grid(row=3, column=0, pady=10, sticky="ew")
        self.list_frame.grid(row=4, column=0, pady=10, sticky="nsew")
        
        # 控制按钮布局
        self.start_btn.grid(row=0, column=0, padx=5)
        self.pause_btn.grid(row=0, column=1, padx=5)
        self.stop_btn.grid(row=0, column=2, padx=5)
        self.save_btn.grid(row=0, column=3, padx=5)
        self.delete_btn.grid(row=0, column=4, padx=5)
        self.clear_btn.grid(row=0, column=5, padx=5)
        
        # 倒计时输入布局
        self.hours_entry.grid(row=0, column=1, padx=5)
        self.minutes_entry.grid(row=0, column=3, padx=5)
        self.seconds_entry.grid(row=0, column=5, padx=5)
        self.countdown_frame.grid_remove()
        
        # 计时列表布局
        self.timer_tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
        self.scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
        
        # 配置容器扩展比例
        tab1.columnconfigure(0, weight=1)
        for i in range(4):
            tab1.rowconfigure(i, weight=0)
        tab1.rowconfigure(4, weight=3)  # 增大列表区域权重


        # 设置最小显示尺寸
        self.notebook.master.minsize(700, 550)


    def create_stats_tab(self):
        """创建统计选项卡"""
        tab2 = ttk.Frame(self.notebook)
        self.notebook.add(tab2, text="统计")

        # 主容器
        main_frame = ttk.Frame(tab2)
        main_frame.pack(fill=tk.BOTH, expand=True, padx=15, pady=15)

        # 周统计部分
        weekly_frame = ttk.LabelFrame(main_frame, text="周统计")
        weekly_frame.pack(fill=tk.X, pady=15)

        self.weekly_tree = ttk.Treeview(
            weekly_frame,
            columns=('week', 'duration'),
            show='headings',
            height=6
        )
        self.weekly_tree.heading('week', text='周')
        self.weekly_tree.heading('duration', text='总时长')
        self.weekly_tree.column('week', width=120, anchor='center')
        self.weekly_tree.column('duration', width=200, anchor='center')
        self.weekly_tree.pack(fill=tk.X)

        # 热力图部分
        heatmap_frame = ttk.LabelFrame(main_frame, text="活动热力图")
        heatmap_frame.pack(fill=tk.X, pady=15)  # 改为水平填充，取消垂直扩展

        # 设置画布固定宽度
        self.canvas = tk.Canvas(heatmap_frame, bg='white', width=300, height=200)  # 明确设置画布宽度
        scroll_x = ttk.Scrollbar(heatmap_frame, orient="horizontal", command=self.canvas.xview)
        scroll_y = ttk.Scrollbar(heatmap_frame, orient="vertical", command=self.canvas.yview)
        self.canvas.configure(xscrollcommand=scroll_x.set, yscrollcommand=scroll_y.set)

        # 调整布局权重
        heatmap_frame.columnconfigure(0, weight=1)
        heatmap_frame.rowconfigure(0, weight=1)

        # 使用grid布局更精确控制
        self.canvas.grid(row=0, column=0, sticky="nsew")
        scroll_y.grid(row=0, column=1, sticky="ns")
        scroll_x.grid(row=1, column=0, sticky="ew")

        # 刷新按钮
        # 最佳实践：创建专用控制面板框架
        control_panel = ttk.Frame(main_frame)
        control_panel.pack(side=tk.BOTTOM, fill=tk.X)
        refresh_btn = ttk.Button(control_panel, text="刷新数据", command=self.update_stats)
        refresh_btn.pack(side=tk.RIGHT, padx=5)


        # 初始化热力图
        self.cell_size = 15
        self.margin = 2
        self.update_stats()

    def setup_bindings(self):
        """设置事件绑定"""
        self.root.bind("<Return>", lambda e: self.start_timer())
        for entry in [self.hours_entry, self.minutes_entry, self.seconds_entry]:
            entry.bind("<FocusIn>", self.on_entry_focus)
            entry.bind("<Key>", self.validate_numeric_input)

    def update_stats(self):
        """更新统计数据显示"""
        analyzer = StatsAnalyzer()
        
        # 更新周统计
        for item in self.weekly_tree.get_children():
            self.weekly_tree.delete(item)
        for week, total in analyzer.get_weekly_stats().items():
            self.weekly_tree.insert('', 'end', values=(
                week,
                analyzer.format_duration(total)
            ))

        # 更新热力图
        self.canvas.delete("all")
        
        # 获取颜色数据和时长数据
        color_data = analyzer.get_color_mapping()
        duration_data = analyzer.get_duration_data()
        
        # 生成完整的日期范围（基于数据）
        dates = sorted(duration_data.keys())
        if not dates:
            return

        # 计算布局参数
        start_date = min(dates)
        end_date = max(dates)
        current_date = start_date
        col, row = 0, 0
        month_labels = []

        while current_date <= end_date:
            # 绘制月份标签
            if current_date.day == 1:
                month_name = calendar.month_abbr[current_date.month]
                x = col * (self.cell_size + self.margin) + 5
                month_labels.append((x, month_name))

            # 获取颜色（直接从颜色数据获取）
            fill_color = color_data.get(current_date, "#ebedf0")
            
            # 绘制颜色块
            x0 = col * (self.cell_size + self.margin)
            y0 = row * (self.cell_size + self.margin)


            # 创建矩形并立即绑定事件（确保rect变量在闭包内）
            self._create_heat_cell(
                x0, y0, 
                fill_color, 
                current_date, 
                col, row
            )

            # 更新坐标
            row += 1
            if row >= 7:  # 每周7天
                row = 0
                col += 1
            current_date += timedelta(days=1)

        # 添加月份标签
        for x, text in month_labels:
            self.canvas.create_text(x, -20, anchor=tk.NW, text=text)

        # 更新画布滚动区域
        self.canvas.configure(scrollregion=self.canvas.bbox("all"))

    def _create_heat_cell(self, x0, y0, color, date, col, row):
        """创建单个热力单元格"""
        # 绘制矩形
        rect = self.canvas.create_rectangle(
            x0, y0,
            x0 + self.cell_size, y0 + self.cell_size,
            fill=color,
            outline="",
            tags=("heat_cell", str(date))
        )
        
         # 修复闭包参数：仅传递event和date
        def make_tooltip(event, d=date):
            self._show_tooltip(event, d)
        
        self.canvas.tag_bind(rect, "<Enter>", make_tooltip)

    def _show_tooltip(self, event, date):
        """显示悬浮提示"""
        # 销毁已存在的提示框
        if hasattr(self, "_current_tooltip"):
            self._current_tooltip.destroy()

        analyzer = StatsAnalyzer()
        duration_data = analyzer.get_duration_data()
        total = duration_data.get(date, 0)
        
        # 创建提示框
        self._current_tooltip = tk.Toplevel()
        tooltip = self._current_tooltip
        tooltip.wm_overrideredirect(True)
        
        # 计算提示位置（跟随鼠标）
        x_pos = event.x_root + 10
        y_pos = event.y_root + 10
        tooltip.geometry(f"+{x_pos}+{y_pos}")
        
        # 添加内容
        label = ttk.Label(tooltip, text=f"{date.strftime('%Y-%m-%d')}\n{analyzer.format_duration(total)}",
                        background="#ffffe0", relief="solid", borderwidth=1)
        label.pack()
        
        # 绑定销毁事件
        # 1. 鼠标离开提示框
        tooltip.bind("<Leave>", lambda e: tooltip.destroy())
        # 2. 鼠标移动超过2像素
        tooltip.bind("<Motion>", lambda e: tooltip.destroy() if abs(e.x - event.x) > 2 or abs(e.y - event.y) > 2 else None)
        # 3. 2秒后自动消失
        tooltip.after(2000, tooltip.destroy)

    def on_mode_change(self):
        """处理模式切换"""
        # 保存当前模式状态
        previous_mode = "countdown" if self.countdown_frame.winfo_ismapped() else "countup"
        new_mode = self.timer_mode.get()
        
        # 如果模式没有实际变化则直接返回
        if previous_mode == new_mode:
            return
        
        # 暂停当前计时（如果正在运行）
        if self.timer.running and not self.timer.paused:
            self.timer.pause()
            self.status_label.config(text=f"已暂停（切换到{new_mode}模式）")
            self.pause_btn.config(text="继续")

        # 更新界面元素
        if new_mode == "countdown":
            self.countdown_frame.grid()
            self.hours_entry.focus_set()
            # 自动填充当前计时值（如果处于暂停状态）
            if self.timer.paused and previous_mode == "countup":
                total = int(self.current_seconds)
                hours = total // 3600
                minutes = (total % 3600) // 60
                seconds = total % 60
                self.hours_entry.delete(0, tk.END)
                self.hours_entry.insert(0, str(hours))
                self.minutes_entry.delete(0, tk.END)
                self.minutes_entry.insert(0, str(minutes))
                self.seconds_entry.delete(0, tk.END)
                self.seconds_entry.insert(0, str(seconds))
        else:
            self.countdown_frame.grid_remove()

        # 更新按钮状态
        self.toggle_buttons(self.timer.running)

    def validate_numeric_input(self, event):
        """限制只能输入数字"""
        widget = event.widget
        if event.char not in ("", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "\b"):
            return "break"

    def on_entry_focus(self, event):
        """输入框获得焦点时全选文本"""
        event.widget.select_range(0, tk.END)

    def start_timer(self):
        """启动计时"""
        try:
            if self.timer_mode.get() == "countdown":
                hours = self.get_valid_entry(self.hours_entry, 0, 23)
                minutes = self.get_valid_entry(self.minutes_entry, 0, 59)
                seconds = self.get_valid_entry(self.seconds_entry, 0, 59)
                total = hours*3600 + minutes*60 + seconds
                if total == 0:
                    raise ValueError("倒计时时间不能为0")
                self.timer.countdown([(hours, minutes, seconds)])
                self.status_label.config(text="倒计时运行中...")
            else:
                self.timer.start()
                self.status_label.config(text="正计时运行中...")
            
            # 更新按钮状态
            self.toggle_buttons(True)
                
        except ValueError as e:
            messagebox.showerror("输入错误", str(e))
        except Exception as e:
            messagebox.showerror("错误", f"启动失败: {str(e)}")

    def toggle_buttons(self, running):
        """切换按钮状态"""
        self.start_btn.config(state=tk.DISABLED if running else tk.NORMAL)
        self.pause_btn.config(state=tk.NORMAL if running else tk.DISABLED)
        self.stop_btn.config(state=tk.NORMAL if running else tk.DISABLED)
        
        # 同步暂停按钮状态
        if self.timer.paused:
            self.pause_btn.config(text="继续")
            self.status_label.config(text="已暂停")
        else:
            self.pause_btn.config(text="暂停")

    def get_valid_entry(self, widget, min_val, max_val):
        """验证并获取输入值"""
        try:
            value = int(widget.get())
            if not (min_val <= value <= max_val):
                raise ValueError
            return value
        except ValueError:
            widget.delete(0, tk.END)
            widget.insert(0, "0")
            raise ValueError(f"无效输入：允许范围 {min_val}-{max_val}")

    def update_display(self, seconds):
        """更新时间显示"""
        try:
            self.current_seconds = seconds  # 记录当前时间值
            h = int(seconds // 3600)
            m = int((seconds % 3600) // 60)
            s = int(seconds % 60)
            time_format = f"{h:02d}:{m:02d}:{s:02d}"
            # 合并特殊时间显示逻辑
            if h == 0 and m == 10 and s == 30:
                self.time_label.config(text="00:10:30", font=("Arial", 48, "bold"))
                self.time_label.config(foreground="#E91E63")  # 粉色
                self.root.after(1000, lambda: self.time_label.config(foreground="black"))
            elif h == 0 and m == 6 and s == 23:
                self.time_label.config(text="00:06:23", font=("Arial", 48, "bold"))
                self.time_label.config(foreground="#008080")  # 青色
                self.root.after(1000, lambda: self.time_label.config(foreground="black"))
            else:
                self.time_label.config(text=time_format, font=("Arial", 48))
                self.time_label.config(foreground="black")
        except Exception as e:
            print(f"显示更新错误: {e}")

    def reset_ui(self):
        """重置界面状态"""
        self.time_label.config(text="00:00:00")
        self.status_label.config(text="就绪")
        self.toggle_buttons(False)

    def on_closing(self):
        """关闭窗口处理"""
        self.timer.stop()
        self.root.destroy()

    def on_complete(self):
        """计时完成回调"""
        self.status_label.config(text="计时完成！")
        if self.timer_mode.get() == "countdown":
            # messagebox.showinfo("完成", "倒计时已结束！")
            self.toggle_buttons(False)

    def pause_timer(self):
        """暂停/继续计时"""
        try:
            if self.timer.paused:
                # 恢复前检查模式是否变化
                current_mode = "countdown" if self.countdown_frame.winfo_ismapped() else "countup"
                if current_mode != self.timer_mode.get():
                    messagebox.showinfo("提示", "请先确认模式切换")
                    return
                    
                self.timer.resume()
                mode_text = "正计时中..." if current_mode == "countup" else "倒计时中..."
                self.status_label.config(text=mode_text)
                self.pause_btn.config(text="暂停")
            else:
                self.timer.pause()
                self.status_label.config(text="已暂停")
                self.pause_btn.config(text="继续")
        except Exception as e:
            messagebox.showerror("错误", f"操作失败: {str(e)}")

    def stop_timer(self):
        """停止计时"""
        try:
            # 获取当前时间值
            current_seconds = self.current_seconds
            
            # 停止计时器
            self.timer.stop()
            
            # 只有当有有效时间时才询问保存
            if current_seconds > 0:
                # 创建自定义对话框
                save_dialog = tk.Toplevel(self.root)
                save_dialog.title("保存确认")
                save_dialog.geometry("300x100")
                save_dialog.resizable(False, False)
                
                # 居中对话框
                main_window_x = self.root.winfo_x()
                main_window_y = self.root.winfo_y()
                main_window_width = self.root.winfo_width()
                dialog_x = main_window_x + (main_window_width - 300) // 2
                save_dialog.geometry(f"+{dialog_x}+{main_window_y+50}")
                
                # 添加内容
                msg = f"当前计时：{self.time_label.cget('text')}\n是否保存本次计时？"
                ttk.Label(save_dialog, text=msg).pack(pady=10)
                
                # 按钮容器
                btn_frame = ttk.Frame(save_dialog)
                btn_frame.pack(pady=5)
                
                # 保存按钮
                ttk.Button(btn_frame, text="保存", 
                        command=lambda: self._handle_stop_save(save_dialog, current_seconds)
                        ).grid(row=0, column=0, padx=5)
                
                # 不保存按钮
                ttk.Button(btn_frame, text="不保存", 
                        command=lambda: self._handle_stop_nosave(save_dialog)
                        ).grid(row=0, column=1, padx=5)
                
                # 取消按钮
                ttk.Button(btn_frame, text="取消", 
                        command=save_dialog.destroy
                        ).grid(row=0, column=2, padx=5)
                
                # 使对话框保持最前
                save_dialog.grab_set()
                self.root.wait_window(save_dialog)
            else:
                # 无有效时间直接重置界面
                self._reset_after_stop()

        except Exception as e:
            messagebox.showerror("错误", f"停止失败: {str(e)}")

    def _handle_stop_save(self, dialog, seconds):
        """处理保存操作"""
        dialog.destroy()
        try:
            h = int(seconds // 3600)
            m = int((seconds % 3600) // 60)
            s = int(seconds % 60)
            save_timer(h, m, s)
            self._refresh_timer_list()
            messagebox.showinfo("已保存", "计时记录已保存")
        except Exception as e:
            messagebox.showerror("保存失败", str(e))
        finally:
            self._reset_after_stop()

    def _handle_stop_nosave(self, dialog):
        """处理不保存操作"""
        dialog.destroy()
        self._reset_after_stop()

    def _reset_after_stop(self):
        """停止后的界面重置"""
        self.toggle_buttons(False)
        self.time_label.config(text="00:00:00")
        self.status_label.config(text="就绪")
    
        # 重置倒计时输入
        if self.timer_mode.get() == "countdown":
            self.hours_entry.delete(0, tk.END)
            self.minutes_entry.delete(0, tk.END)
            self.seconds_entry.delete(0, tk.END)
            self.hours_entry.insert(0, "0")
            self.minutes_entry.insert(0, "0")
            self.seconds_entry.insert(0, "0")

    def save_timer(self):
        """保存计时设置"""
        try:
            if self.timer_mode.get() == "countup":
                total = int(self.timer.elapsed_seconds)
                if total <= 0:
                    raise ValueError("请先启动正计时")
                hours = total // 3600
                minutes = (total % 3600) // 60
                seconds = total % 60
            else:
                hours = self._validate_entry(self.hours_entry, 0, 23, "小时")
                minutes = self._validate_entry(self.minutes_entry, 0, 59, "分钟")
                seconds = self._validate_entry(self.seconds_entry, 0, 59, "秒")
                if hours + minutes + seconds == 0:
                    raise ValueError("时间不能全为0")

            save_timer(hours, minutes, seconds)
            self._refresh_timer_list()
            messagebox.showinfo("成功", f"已保存: {hours:02d}:{minutes:02d}:{seconds:02d}")

        except Exception as e:
            messagebox.showerror("错误", str(e))

    def _validate_entry(self, entry, min_val, max_val, field_name):
        """增强版输入验证"""
        try:
            input_str = entry.get().strip()
            if not input_str:
                raise ValueError(f"{field_name}不能为空")
                
            value = int(input_str)
            if not (min_val <= value <= max_val):
                # 自动修正越界值
                corrected = max(min_val, min(value, max_val))
                entry.delete(0, tk.END)
                entry.insert(0, str(corrected))
                raise ValueError(f"{field_name}已自动修正为{corrected}")
                
            return value
        except ValueError:
            # 重置为默认值
            entry.delete(0, tk.END)
            entry.insert(0, "0")
            raise ValueError(f"无效的{field_name}输入，已重置为0")

    def clear_timers(self):
        """清空计时记录"""
        if messagebox.askyesno("确认", "确定要清空所有记录吗？"):
            clear_timers()
            self._refresh_timer_list()

    def _refresh_timer_list(self):
        """刷新计时列表"""
        for item in self.timer_tree.get_children():
            self.timer_tree.delete(item)
        try:
            for timer_id, hours, minutes, seconds, created_at in get_timers():
                time_str = f"{hours:02d}:{minutes:02d}:{seconds:02d}"
                # 转换时间戳格式
                try:
                    dt = datetime.strptime(str(created_at), "%Y-%m-%d %H:%M:%S")
                    created_str = dt.strftime("%Y-%m-%d %H:%M:%S")
                except Exception:
                    created_str = str(created_at)
                # 判断标签
                tag = 'default_black'
                if hours == 0 and minutes == 10 and seconds == 30:
                    tag = 'special_pink'
                elif hours == 0 and minutes == 6 and seconds == 23:
                    tag = 'special_teal'
                self.timer_tree.insert(
                    '',
                    'end',
                    values=(time_str, created_str),
                    iid=str(timer_id),
                    tags=(tag,)
                )
        except Exception as e:
            messagebox.showerror("错误", f"加载记录失败: {str(e)}")
    
    def delete_timer(self):
        """删除选中记录"""
        selected_items = self.timer_tree.selection()
        if not selected_items:
            messagebox.showwarning("警告", "请先选择要删除的记录")
            return
            
        if messagebox.askyesno("确认删除", "确定要删除选中的记录吗？"):
            success = True
            for item_id in selected_items:
                try:
                    delete_timer_by_id(int(item_id))
                except Exception as e:
                    success = False
                    messagebox.showerror("错误", f"删除失败: {str(e)}")
            
            if success:
                self._refresh_timer_list()


if __name__ == "__main__":
    root = tk.Tk()
    app = TimerGUI(root)
    root.mainloop()